package com.yn.club.subject.domain.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yn.club.common.util.PageReq;
import com.yn.club.common.util.PageResp;
import java.io.Serializable;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.yn.club.subject.domain.entity.SubjectCategoryDO;
import com.yn.club.subject.infra.basic.entity.SubjectCategory;
import com.yn.club.subject.domain.service.SubjectCategoryDomainService;
import com.yn.club.subject.infra.basic.service.SubjectCategoryService;
import com.yn.club.subject.domain.convert.SubjectCategoryDomainConverter;


/**
 * 题目分类(SubjectCategory)表服务接口实现类
 *
 * @author YN
 * @since 2025-01-21 17:36:34
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class SubjectCategoryDomainServiceImpl implements SubjectCategoryDomainService {

  private final SubjectCategoryService subjectCategoryService;
  private final SubjectCategoryDomainConverter subjectCategoryDomainConverter;


  /**
   * 分页
   */
  @Override
  public PageResp<SubjectCategoryDO> page(PageReq pageReq, SubjectCategoryDO query){
    QueryWrapper<SubjectCategory> querywrapper = new QueryWrapper<SubjectCategory>()
        .eq(query.getId() != null, "id", query.getId())
        .orderByDesc("id");
        
    Page<SubjectCategory> page = subjectCategoryService.page(
      new Page<>(pageReq.getPageIndex(),pageReq.getPageSize()),querywrapper);
    List<SubjectCategory> list = page.getRecords();  
    return PageResp.of(page,subjectCategoryDomainConverter.convertEntityToDo(list));
  }

  /**
   * 新增数据
   */
  @Override
  public Boolean insert(SubjectCategoryDO obj){
    SubjectCategory subjectCategory = subjectCategoryDomainConverter.convertDoToEntity(obj);
    return subjectCategoryService.save(subjectCategory);
  };


  /**
   * 更新数据
   */
  @Override
  public Boolean updateById(SubjectCategoryDO obj){
    SubjectCategory subjectCategory = subjectCategoryDomainConverter.convertDoToEntity(obj);
    return subjectCategoryService.updateById(subjectCategory);
  };

  /**
   * 批量删除
   */
  @Override
  public Boolean delete(List<Integer> ids){
    return subjectCategoryService.removeByIds(ids);
  };

  /**
   * 根据id查找
   */
  @Override
  public SubjectCategoryDO getById(Serializable id){
    SubjectCategory subjectCategory = subjectCategoryService.getById(id);
    return  subjectCategoryDomainConverter.convertEntityToDo(subjectCategory);
  };


}

